<template>
  <div>
    <van-nav-bar
      title="更新昵称"
      left-text="取消"
      right-text="保存"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />

    <van-field
      v-model="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="11"
      placeholder="请输入昵称"
      show-word-limit
    />
  </div>
</template>

<script>
import { setUserInfoAPI } from '@/api'
export default {
  props: {
    name: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      message: this.name
    }
  },
  methods: {
    onClickLeft() {
      this.$emit('uuname')
    },
    async onClickRight() {
      this.$toast.loading({
        message: '加载中。。。',
        forbidClick: true
      })
      await setUserInfoAPI({
        name: this.message
      })
      this.$emit('update:name', this.message)
      this.$emit('uuname')
      this.$toast.success('更新昵称成功')
    }
  }
}
</script>

<style></style>